﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _21.GenerateAllCombinations
{
    class GenerateAllCombinations
    {
        static void GetCombinations(int[] arr, int index, int n, int number)
        {
            if (index == arr.Length)
            {
                for (int i = 0; i < arr.Length; i++)
                {
                    Console.Write(arr[i] + " ");
                }
                Console.WriteLine();
            }
            else
            {
                for (int i = number; i <= n; i++)
                {
                    arr[index] = i;
                    GetCombinations(arr, index + 1, n,i+1);
                }
            }
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Enter N and K to see all combinations of K distinct elements from the set [1..N]");
            Console.Write("Enter N=");
            int n = int.Parse(Console.ReadLine());
            Console.Write("Enter K=");
            int k = int.Parse(Console.ReadLine());
            int[] combinations = new int[k];
            GetCombinations(combinations, 0, n,1);
        }
    }
}
